package com.qing.microservices.shirostudy.common.utils;

import cn.hutool.crypto.SmUtil;

import java.nio.charset.StandardCharsets;

/**
 * @author guoqf
 */
public class CryptoUtil {

    public static final int DEFAULT_SALT_LENGTH = 8;

    public static String encryptPasswd(String passwd) {
        return SmUtil.sm3WithSalt(SaltUtil.getSalt(DEFAULT_SALT_LENGTH).getBytes(StandardCharsets.UTF_8)).digestHex(passwd);
    }
    public static String encryptPasswd(String passwd, String salt) {
        return SmUtil.sm3WithSalt(salt.getBytes(StandardCharsets.UTF_8)).digestHex(passwd);
    }
}
